package com.wqtz.chechai.view.activities;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.Toast;

import com.wqtz.chechai.R;
import com.wqtz.chechai.base.BaseActivity;
import com.wqtz.chechai.bean.ItemType;
import com.wqtz.chechai.bean.LoanDetailInfoBean;
import com.wqtz.chechai.presenter.BasePresent;
import com.wqtz.chechai.utils.LogUtils;
import com.wqtz.chechai.view.fragments.DataArchiveFragment;
import com.wqtz.chechai.view.fragments.LoanProgressFragment;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * 项目名称： CheChai
 * 创建人 :  Kisum
 * 创建时间: 2017/1/19
 * 放款详情页面
 */
public class LoanInfoActivity extends BaseActivity {
    /**
     * 放款的四种状态：审核中 审核成功 被拒绝 取消
     */
    private final int CHECKING = 0;
    private final int CHECK_SUCCESSED = 1;
    private final int REFUSED = 2;
    private final int CANCELD = 3;
    /**
     * 退款的三种状态： 退款审核中 已退款 退款被拒绝
     */
    private final int REFUND_CHECKING = 4;
    private final int REFUND_CHECK_SUCCESSED = 5;
    private final int REFUND_REFUSED = 6;
    /**
     * 解约的三种状态： 解约审核中 已解约 解约被拒绝
     */
    private final int BREAK_CHECKING = 7;
    private final int BREAK_CHECK_SUCCESSED = 8;
    private final int BREAK_REFUSED = 9;
    /**
     * 归档的三种状态： 归档审核中 已归档 归档被拒绝
     */
    private final int FILE_CHECKING = 10;
    private final int FILE_CHECK_SUCCESSED = 11;
    private final int FILE_REFUSED = 12;
    /**
     * 续约的三种状态： 续约审核中 已续约 续约被拒绝
     */
    private final int RENEW_CHECKING = 13;
    private final int RENEW_CHECK_SUCCESSED = 14;
    private final int RENEW_REFUSED = 15;

    @BindView(R.id.iv_back)
    ImageView mIvBack;
    @BindView(R.id.tv_title)
    TextView mTvTitle;
    @BindView(R.id.ll_loaninfo_contract)
    LinearLayout mLlLoaninfoContract;
    @BindView(R.id.rb_data_archive)
    RadioButton mRbDataArchive;
    @BindView(R.id.rb_progress)
    RadioButton mRbProgress;
    @BindView(R.id.rg_data_progress)
    RadioGroup mRgDataProgress;
    @BindView(R.id.framlayout_loan_info)
    FrameLayout mFramlayoutLoanInfo;
    @BindView(R.id.iv_check_status)
    ImageView mIvCheckStatus;
    @BindView(R.id.btn_loan_action)
    Button mBtnLoanAction;
    @BindView(R.id.ll_loaninfo_carinfo)
    LinearLayout mLlLoaninfoCarinfo;
    @BindView(R.id.tv_check_status)
    TextView mTvCheckStatus;
    @BindView(R.id.btn_loan_action_gray)
    Button mBtnLoanActionGray;
    @BindView(R.id.btn_loan_action_first)
    Button mBtnLoanActionFirst;
    @BindView(R.id.btn_loan_action_first_gray)
    Button mBtnLoanActionFirstGray;
    @BindView(R.id.tv_loan_renewal_once)
    TextView mTvLoanRenewalOnce;
    @BindView(R.id.tv_loan_detail_price)
    TextView mTvLoanDetailPrice;
    @BindView(R.id.tv_loan_period)
    TextView mTvLoanPeriod;


    @Override
    public void init() {
        EventBus.getDefault().register(this);
        ButterKnife.bind(this);
        Intent intent = getIntent();
        int type = intent.getIntExtra("type", -1);
        //将type存入ItemType
        ItemType mItemType = new ItemType();
        mItemType.setType(type);
        //发布消息，将数据传给fragment
        EventBus.getDefault().postSticky(mItemType);
        switch (type) {
            /**
             * 放款的四种状态：审核中 审核成功 被拒绝 取消
             */
            case CHECKING:
                LogUtils.e("type:" + type);
                mIvCheckStatus.setImageResource(R.mipmap.loan_checking);
                mTvCheckStatus.setText("审核中");
                mBtnLoanAction.setText("取消放款");
                mBtnLoanAction.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        //取消放款
                    }
                });
                break;
            case CHECK_SUCCESSED:
                LogUtils.e("type:" + type);
                mIvCheckStatus.setImageResource(R.mipmap.loan_passed);
                mTvCheckStatus.setText("已下款");
                mBtnLoanAction.setText("资金回执");
                mBtnLoanAction.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        //资金回执
                        Intent toCashReceiptIntent = new Intent(LoanInfoActivity.this, CashReceiptActivity.class);
                        startActivity(toCashReceiptIntent);
                    }
                });
                break;
            case REFUSED:
                LogUtils.e("type:" + type);
                mIvCheckStatus.setImageResource(R.drawable.loan_rejected);
                mTvCheckStatus.setText("被拒绝");
                mBtnLoanAction.setText("再次申请");
                mBtnLoanAction.setVisibility(View.INVISIBLE);
                mBtnLoanActionGray.setVisibility(View.VISIBLE);
                //不可点击
                mBtnLoanActionGray.setClickable(false);
                break;
            case CANCELD:
                LogUtils.e("type:" + type);
                mIvCheckStatus.setImageResource(R.mipmap.loan_canceled);
                mTvCheckStatus.setText("已取消");
                mBtnLoanAction.setText("再次申请");
                mBtnLoanAction.setVisibility(View.INVISIBLE);
                mBtnLoanActionGray.setVisibility(View.VISIBLE);
                //不可点击
                mBtnLoanActionGray.setClickable(false);
                break;
            /**
             * 退款的三种状态： 退款审核中 已退款 退款被拒绝
             */
            case REFUND_CHECKING:
                LogUtils.e("type:" + type);
                mIvCheckStatus.setImageResource(R.mipmap.loan_refund_checking);
                mTvCheckStatus.setText("退款审核中");
                mBtnLoanActionGray.setText("再次申请");
                mBtnLoanAction.setVisibility(View.INVISIBLE);
                mBtnLoanActionGray.setVisibility(View.VISIBLE);
                //不可点击
                mBtnLoanActionGray.setClickable(false);
                break;
            case REFUND_CHECK_SUCCESSED:
                LogUtils.e("type:" + type);
                mIvCheckStatus.setImageResource(R.mipmap.loan_refund_checked);
                mTvCheckStatus.setText("已退款");
                mBtnLoanActionGray.setText("再次申请");
                mBtnLoanAction.setVisibility(View.INVISIBLE);
                mBtnLoanActionGray.setVisibility(View.VISIBLE);
                //不可点击
                mBtnLoanActionGray.setClickable(false);
                break;
            case REFUND_REFUSED:
                LogUtils.e("type:" + type);
                mIvCheckStatus.setImageResource(R.mipmap.loan_refund_rejected);
                mTvCheckStatus.setText("退款被拒绝");
                mBtnLoanAction.setText("再次申请");
                //再次申请
                requestAgain();
                break;
            /**
             * 解约的三种状态： 解约审核中 已解约 解约被拒绝
             */
            case BREAK_CHECKING:
                LogUtils.e("type:" + type);
                mIvCheckStatus.setImageResource(R.mipmap.loan_break_checking);
                mTvCheckStatus.setText("解约审核中");
                mBtnLoanAction.setText("再贷一次");
                mBtnLoanAction.setVisibility(View.INVISIBLE);
                mBtnLoanActionGray.setVisibility(View.VISIBLE);
                //不可点击
                mBtnLoanActionGray.setClickable(false);
                break;
            case BREAK_CHECK_SUCCESSED:
                LogUtils.e("type:" + type);
                mIvCheckStatus.setImageResource(R.mipmap.loan_breaked);
                mTvCheckStatus.setText("已解约");
                mBtnLoanAction.setText("再贷一次");
                mBtnLoanAction.setVisibility(View.INVISIBLE);
                mBtnLoanActionGray.setVisibility(View.VISIBLE);
                //再贷一次
                loanAgain();
                break;
            case BREAK_REFUSED:
                LogUtils.e("type:" + type);
                mIvCheckStatus.setImageResource(R.mipmap.loan_break_rejected);
                mTvCheckStatus.setText("解约被拒绝");
                mBtnLoanAction.setText("再次申请");
                //再次申请
                requestAgain();
                break;
            /**
             * 归档的三种状态： 归档审核中 已归档 归档被拒绝
             */
            case FILE_CHECKING:
                LogUtils.e("type:" + type);
                mIvCheckStatus.setImageResource(R.mipmap.loan_file_checking);
                mTvCheckStatus.setText("归档审核中");
                mBtnLoanActionFirst.setVisibility(View.INVISIBLE);
                mBtnLoanActionFirstGray.setVisibility(View.VISIBLE);
                mBtnLoanActionFirstGray.setText("续约");
                mBtnLoanActionGray.setText("解约");
                mBtnLoanActionGray.setVisibility(View.VISIBLE);
                mBtnLoanAction.setVisibility(View.INVISIBLE);
                //不可点击
                mBtnLoanActionGray.setClickable(false);
                mBtnLoanActionFirstGray.setClickable(false);
                break;
            case FILE_CHECK_SUCCESSED:
                LogUtils.e("type:" + type);
                mIvCheckStatus.setImageResource(R.mipmap.loan_filed);
                mTvCheckStatus.setText("已归档");
                mBtnLoanActionFirst.setVisibility(View.VISIBLE);
                mBtnLoanActionFirst.setText("续约");
                mBtnLoanAction.setText("解约");
                mBtnLoanActionFirst.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        //续约
                        Intent toRenewalIntent = new Intent(LoanInfoActivity.this, RenewalApplicationActivity.class);
                        startActivity(toRenewalIntent);
                    }
                });
                mBtnLoanAction.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        //解约
                        Intent toBreakIntent = new Intent(LoanInfoActivity.this, UploadBreakReceiptActivity.class);
                        startActivity(toBreakIntent);
                    }
                });
                break;
            case FILE_REFUSED:
                LogUtils.e("type:" + type);
                mIvCheckStatus.setImageResource(R.mipmap.loan_file_rejected);
                mTvCheckStatus.setText("归档被拒绝");
                mBtnLoanAction.setText("再次申请");
                //再次申请
                requestAgain();
                break;
            /**
             * 续约的三种状态： 续约审核中 已续约 续约被拒绝
             */
            case RENEW_CHECKING:
                LogUtils.e("type:" + type);
                mIvCheckStatus.setImageResource(R.mipmap.loan_renewal_checking);
                mTvCheckStatus.setText("续约审核中");
                mBtnLoanActionFirst.setVisibility(View.INVISIBLE);
                mBtnLoanActionFirstGray.setVisibility(View.VISIBLE);
                mBtnLoanActionFirstGray.setText("续约");
                mBtnLoanActionGray.setText("解约");
                mBtnLoanActionGray.setVisibility(View.VISIBLE);
                mBtnLoanAction.setVisibility(View.INVISIBLE);
                //不可点击
                mBtnLoanActionGray.setClickable(false);
                mBtnLoanActionFirstGray.setClickable(false);
                //设置借款期数不可见
                mTvLoanPeriod.setVisibility(View.INVISIBLE);
                //续一次
                mTvLoanRenewalOnce.setVisibility(View.VISIBLE);
                break;
            case RENEW_CHECK_SUCCESSED:
                LogUtils.e("type:" + type);
                mIvCheckStatus.setImageResource(R.mipmap.loan_renewaled);
                mTvCheckStatus.setText("已续约");
                mBtnLoanActionFirst.setVisibility(View.VISIBLE);
                mBtnLoanActionFirst.setText("续约");
                mBtnLoanAction.setText("解约");
                mBtnLoanActionFirst.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        //续约
                        Intent toRenewalIntent = new Intent(LoanInfoActivity.this, RenewalApplicationActivity.class);
                        startActivity(toRenewalIntent);
                    }
                });
                mBtnLoanAction.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        //解约
                        Intent toBreakIntent = new Intent(LoanInfoActivity.this, UploadBreakReceiptActivity.class);
                        startActivity(toBreakIntent);
                    }
                });
                //设置借款期数不可见
                mTvLoanPeriod.setVisibility(View.INVISIBLE);
                //续一次
                mTvLoanRenewalOnce.setVisibility(View.VISIBLE);
                break;
            case RENEW_REFUSED:
                LogUtils.e("type:" + type);
                mIvCheckStatus.setImageResource(R.mipmap.loan_renewal_rejected);
                mTvCheckStatus.setText("续约被拒绝");
                mBtnLoanAction.setText("再次申请");
                //续一次
                mTvLoanRenewalOnce.setVisibility(View.VISIBLE);
                //再次申请
                requestAgain();
                break;
        }

    }


    /**
     * 再次申请
     */
    private void requestAgain() {
        mBtnLoanAction.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //再次申请
            }
        });
    }

    /**
     * 再贷一次
     */
    private void loanAgain() {
        mBtnLoanActionGray.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //再贷一次
            }
        });
    }

    @Override
    public void loadData() {
        //默认资料归档页面
        fragmentManager(R.id.framlayout_loan_info, new DataArchiveFragment(), "DataArchiveFragment");

    }

    @Override
    public int setContentViews() {
        return R.layout.activity_loan_info;
    }

    @Override
    public BasePresent createPresenter() {
        return null;
    }

    @OnClick({R.id.iv_back, R.id.ll_loaninfo_carinfo, R.id.ll_loan_detail, R.id.ll_loan_user_info, R.id.ll_loaninfo_contract, R.id.rb_data_archive, R.id.rb_progress, R.id.btn_loan_action})
    public void onClick(View view) {
        switch (view.getId()) {
            //返回
            case R.id.iv_back:
                this.finish();
                break;
            //车辆详情
            case R.id.ll_loaninfo_carinfo:
                Intent toLoanCarInfoIntent = new Intent(this, LoanCarInfoActivity.class);
                startActivity(toLoanCarInfoIntent);
                break;
            //借款详情
            case R.id.ll_loan_detail:
                Intent toLoanDetailIntent = new Intent(this, LoanDetailInfoActivity.class);
                startActivity(toLoanDetailIntent);
                break;
            //借款人详情
            case R.id.ll_loan_user_info:
                Intent toLoanUserInfoIntent = new Intent(this, LoanUserInfoActivity.class);
                startActivity(toLoanUserInfoIntent);
                break;
            //合同生成
            case R.id.ll_loaninfo_contract:
                Intent toLoanContractInfoIntent = new Intent(this, LoanContractInfoActivity.class);
                startActivity(toLoanContractInfoIntent);
                break;
            //资料归档
            case R.id.rb_data_archive:
                this.fragmentManager(R.id.framlayout_loan_info, new DataArchiveFragment(), "DataArchiveFragment");
                break;
            //进展
            case R.id.rb_progress:
                this.fragmentManager(R.id.framlayout_loan_info, new LoanProgressFragment(), "LoanProgressFragment");
                break;
            //放款动作
            case R.id.btn_loan_action:
                Toast.makeText(this, "取消放款", Toast.LENGTH_SHORT).show();
                break;
        }

    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        //接受返回的type
        switch (requestCode) {
            /**
             * 放款的四种状态：审核中 审核成功 被拒绝 取消
             */
            case CHECKING:
                LogUtils.e("type:" + requestCode);
                mIvCheckStatus.setImageResource(R.mipmap.loan_checking);
                mTvCheckStatus.setText("审核中");
                mBtnLoanAction.setText("取消放款");
                mBtnLoanAction.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        //取消放款
                    }
                });
                break;
            case CHECK_SUCCESSED:
                LogUtils.e("type:" + requestCode);
                mIvCheckStatus.setImageResource(R.mipmap.loan_passed);
                mTvCheckStatus.setText("已下款");
                mBtnLoanAction.setText("资金回执");
                mBtnLoanAction.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        //资金回执
                        Intent toCashReceiptIntent = new Intent(LoanInfoActivity.this, CashReceiptActivity.class);
                        startActivity(toCashReceiptIntent);
                    }
                });
                break;
            case REFUSED:
                LogUtils.e("type:" + requestCode);
                mIvCheckStatus.setImageResource(R.drawable.loan_rejected);
                mTvCheckStatus.setText("被拒绝");
                mBtnLoanAction.setText("再次申请");
                mBtnLoanAction.setVisibility(View.INVISIBLE);
                mBtnLoanActionGray.setVisibility(View.VISIBLE);
                //不可点击
                mBtnLoanActionGray.setClickable(false);
                break;
            case CANCELD:
                LogUtils.e("type:" + requestCode);
                mIvCheckStatus.setImageResource(R.mipmap.loan_canceled);
                mTvCheckStatus.setText("已取消");
                mBtnLoanAction.setText("再次申请");
                mBtnLoanAction.setVisibility(View.INVISIBLE);
                mBtnLoanActionGray.setVisibility(View.VISIBLE);
                //不可点击
                mBtnLoanActionGray.setClickable(false);
                break;
            /**
             * 退款的三种状态： 退款审核中 已退款 退款被拒绝
             */
            case REFUND_CHECKING:
                LogUtils.e("type:" + requestCode);
                mIvCheckStatus.setImageResource(R.mipmap.loan_refund_checking);
                mTvCheckStatus.setText("退款审核中");
                mBtnLoanAction.setText("再次申请");
                mBtnLoanAction.setVisibility(View.INVISIBLE);
                mBtnLoanActionGray.setVisibility(View.VISIBLE);
                //不可点击
                mBtnLoanActionGray.setClickable(false);
                break;
            case REFUND_CHECK_SUCCESSED:
                LogUtils.e("type:" + requestCode);
                mIvCheckStatus.setImageResource(R.mipmap.loan_refund_checked);
                mTvCheckStatus.setText("已退款");
                mBtnLoanAction.setText("再次申请");
                mBtnLoanAction.setVisibility(View.INVISIBLE);
                mBtnLoanActionGray.setVisibility(View.VISIBLE);
                //不可点击
                mBtnLoanActionGray.setClickable(false);
                break;
            case REFUND_REFUSED:
                LogUtils.e("type:" + requestCode);
                mIvCheckStatus.setImageResource(R.mipmap.loan_refund_rejected);
                mTvCheckStatus.setText("退款被拒绝");
                mBtnLoanAction.setText("再次申请");
                //再次申请
                requestAgain();
                break;
            /**
             * 解约的三种状态： 解约审核中 已解约 解约被拒绝
             */
            case BREAK_CHECKING:
                LogUtils.e("type:" + requestCode);
                mIvCheckStatus.setImageResource(R.mipmap.loan_break_checking);
                mTvCheckStatus.setText("解约审核中");
                mBtnLoanAction.setText("再贷一次");
                mBtnLoanAction.setVisibility(View.INVISIBLE);
                mBtnLoanActionGray.setVisibility(View.VISIBLE);
                //不可点击
                mBtnLoanActionGray.setClickable(false);
                break;
            case BREAK_CHECK_SUCCESSED:
                LogUtils.e("type:" + requestCode);
                mIvCheckStatus.setImageResource(R.mipmap.loan_breaked);
                mTvCheckStatus.setText("已解约");
                mBtnLoanAction.setText("再贷一次");
                mBtnLoanAction.setVisibility(View.INVISIBLE);
                mBtnLoanActionGray.setVisibility(View.VISIBLE);
                //再贷一次
                loanAgain();
                break;
            case BREAK_REFUSED:
                LogUtils.e("type:" + requestCode);
                mIvCheckStatus.setImageResource(R.mipmap.loan_break_rejected);
                mTvCheckStatus.setText("解约被拒绝");
                mBtnLoanAction.setText("再次申请");
                //再次申请
                requestAgain();
                break;
            /**
             * 归档的三种状态： 归档审核中 已归档 归档被拒绝
             */
            case FILE_CHECKING:
                LogUtils.e("type:" + requestCode);
                mIvCheckStatus.setImageResource(R.mipmap.loan_file_checking);
                mTvCheckStatus.setText("归档审核中");
                mBtnLoanActionFirst.setVisibility(View.INVISIBLE);
                mBtnLoanActionFirstGray.setVisibility(View.VISIBLE);
                mBtnLoanActionFirstGray.setText("续约");
                mBtnLoanActionGray.setText("解约");
                mBtnLoanActionGray.setVisibility(View.VISIBLE);
                mBtnLoanAction.setVisibility(View.INVISIBLE);
                //不可点击
                mBtnLoanActionGray.setClickable(false);
                mBtnLoanActionFirstGray.setClickable(false);
                break;
            case FILE_CHECK_SUCCESSED:
                LogUtils.e("type:" + requestCode);
                mIvCheckStatus.setImageResource(R.mipmap.loan_filed);
                mTvCheckStatus.setText("已归档");
                mBtnLoanActionFirst.setVisibility(View.VISIBLE);
                mBtnLoanActionFirst.setText("续约");
                mBtnLoanAction.setText("解约");
                mBtnLoanActionFirst.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        //续约
                        Intent toRenewalIntent = new Intent(LoanInfoActivity.this, RenewalApplicationActivity.class);
                        startActivity(toRenewalIntent);
                    }
                });
                mBtnLoanAction.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        //解约
                        Intent toBreakIntent = new Intent(LoanInfoActivity.this, UploadBreakReceiptActivity.class);
                        startActivity(toBreakIntent);
                    }
                });
                break;
            case FILE_REFUSED:
                LogUtils.e("type:" + requestCode);
                mIvCheckStatus.setImageResource(R.mipmap.loan_file_rejected);
                mTvCheckStatus.setText("归档被拒绝");
                mBtnLoanAction.setText("再次申请");
                //再次申请
                requestAgain();
                break;
            /**
             * 续约的三种状态： 续约审核中 已续约 续约被拒绝
             */
            case RENEW_CHECKING:
                LogUtils.e("type:" + requestCode);
                mIvCheckStatus.setImageResource(R.mipmap.loan_renewal_checking);
                mTvCheckStatus.setText("续约审核中");
                mBtnLoanActionFirst.setVisibility(View.INVISIBLE);
                mBtnLoanActionFirstGray.setVisibility(View.VISIBLE);
                mBtnLoanActionFirstGray.setText("续约");
                mBtnLoanActionGray.setText("解约");
                mBtnLoanActionGray.setVisibility(View.VISIBLE);
                mBtnLoanAction.setVisibility(View.INVISIBLE);
                //不可点击
                mBtnLoanActionGray.setClickable(false);
                mBtnLoanActionFirstGray.setClickable(false);
                //设置借款期数不可见
                mTvLoanPeriod.setVisibility(View.INVISIBLE);
                //续一次
                mTvLoanRenewalOnce.setVisibility(View.VISIBLE);
                break;
            case RENEW_CHECK_SUCCESSED:
                LogUtils.e("type:" + requestCode);
                mIvCheckStatus.setImageResource(R.mipmap.loan_renewaled);
                mTvCheckStatus.setText("已续约");
                mBtnLoanActionFirst.setVisibility(View.VISIBLE);
                mBtnLoanActionFirst.setText("续约");
                mBtnLoanAction.setText("解约");
                mBtnLoanActionFirst.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        //续约
                        Intent toRenewalIntent = new Intent(LoanInfoActivity.this, RenewalApplicationActivity.class);
                        startActivity(toRenewalIntent);
                    }
                });
                mBtnLoanAction.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        //解约
                        Intent toBreakIntent = new Intent(LoanInfoActivity.this, UploadBreakReceiptActivity.class);
                        startActivity(toBreakIntent);
                    }
                });
                //设置借款期数不可见
                mTvLoanPeriod.setVisibility(View.INVISIBLE);
                //续一次
                mTvLoanRenewalOnce.setVisibility(View.VISIBLE);
                break;
            case RENEW_REFUSED:
                LogUtils.e("type:" + requestCode);
                mIvCheckStatus.setImageResource(R.mipmap.loan_renewal_rejected);
                mTvCheckStatus.setText("续约被拒绝");
                mBtnLoanAction.setText("再次申请");
                //设置借款期数不可见
                mTvLoanPeriod.setVisibility(View.INVISIBLE);
                //续一次
                mTvLoanRenewalOnce.setVisibility(View.VISIBLE);
                //再次申请
                requestAgain();
                break;
        }
    }

    //接受EventBus消息
    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onLoanDetaiPeriod(LoanDetailInfoBean loanDetailInfoBean) {
        if (loanDetailInfoBean != null) {
            mTvLoanPeriod.setVisibility(View.VISIBLE);
            if (loanDetailInfoBean.getLoanDetailType() == 0) {
                int loanDetailPeriods = loanDetailInfoBean.getLoanDetailPeriods();
                mTvLoanPeriod.setText("第" + loanDetailPeriods + "期");
            }
        }


    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        EventBus.getDefault().unregister(this);
    }

}
